package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.serviceManage.bean.KpiBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.mapper.KpiMapper;
import com.koron.css2.serviceManage.queryBean.KpiQueryBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 根据id查询指标管理信息
 * @author 李攀
 *
 */
public class KpiQuery implements ServerInterface {
	
	private static Logger logger = LogManager.getLogger(KpiQuery.class);
	
	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {

		@SuppressWarnings("rawtypes")
		MessageBean<KpiBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", KpiBean.class);

		try {
			KpiQueryBean bean = JsonUtils.objectToPojo(req.getData(), KpiQueryBean.class);
			KpiMapper mapper = factory.getMapper(KpiMapper.class);
			KpiBean kpibean = mapper.selectKpiById(bean.getKpiId());
			info.setData( kpibean);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}

}
